package anx;

import static org.junit.Assert.assertTrue;
import anx.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that runner Fire 80% of the time.
 * @author Anthony Xu (adapted by code from Philip Johnson)
 *
 */
public class TestRunnerVersusFire extends RobotTestBed {

  /**
   * Specifies that Corners and runner are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Fire,anx.Runner";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * The actual test, which asserts that runner has won at least 60% of fights against Fire.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    // Check to make sure runner won every round.
    assertTrue("Check that Runner beats Fire at least 60% of the time", 
        (results[1].getFirsts() >= getNumRounds() * 6 / 10));
  }
}
